package com.imyours.webservice.services;

import org.hibernate.Session;

import com.imyours.model.user.UserEntity;
import com.imyours.model.util.HibernateUtil;
import com.imyours.webservice.service.Context;
import com.imyours.webservice.service.ContextService;
import com.imyours.webservice.services.annotation.Service;

/**添加新的用户
 * @author SLevenc
 *
 */
@Service(name="addUser")
public class AddUser extends ContextService {

	public AddUser(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public void execute() {
	if(isAdmin()){
		UserEntity newUser = new UserEntity();
		String username = context.getParameter().get("username");
		String password = context.getParameter().get("password");
		String name = context.getParameter().get("realname");
		newUser.setUsername(username);
		newUser.setPassword(password);
		newUser.setRealname(name);
		
		Session se = HibernateUtil.getSessionFactory().openSession();
		se.beginTransaction();
		se.save(newUser);
		se.getTransaction().commit();
		se.close();
		context.success();
	}
	}

}
